package cn.iocoder.yudao.module.blog.convert.postcomment;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.blog.controller.app.post.commentvo.AppBlogPostCommentRespVO;
import cn.iocoder.yudao.module.blog.convert.base.BlogConvert;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.blog.controller.admin.postcomment.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.postcomment.BlogPostCommentDO;

/**
 * 帖子评论 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface BlogPostCommentConvert {

    BlogPostCommentConvert INSTANCE = Mappers.getMapper(BlogPostCommentConvert.class);

    BlogPostCommentDO convert(BlogPostCommentCreateReqVO bean);

    BlogPostCommentDO convert(BlogPostCommentUpdateReqVO bean);

    BlogPostCommentRespVO convert(BlogPostCommentDO bean);

    List<BlogPostCommentRespVO> convertList(List<BlogPostCommentDO> list);

    PageResult<BlogPostCommentRespVO> convertPage(PageResult<BlogPostCommentDO> page);

    List<BlogPostCommentExcelVO> convertList02(List<BlogPostCommentDO> list);

    default AppBlogPostCommentRespVO convertApp(BlogPostCommentDO bean, MemberUserRespDTO memberUserRespDTO){
        if ( bean == null ) {
            return null;
        }

        AppBlogPostCommentRespVO appBlogPostCommentRespVO = new AppBlogPostCommentRespVO();

        appBlogPostCommentRespVO.setMember(BlogConvert.INSTANCE.covnertMember(memberUserRespDTO));
        appBlogPostCommentRespVO.setPostId(bean.getPostId());
        appBlogPostCommentRespVO.setId(bean.getId());
        appBlogPostCommentRespVO.setCreateTime(bean.getCreateTime());
        appBlogPostCommentRespVO.setMainCommentId(bean.getMainCommentId());
        appBlogPostCommentRespVO.setMemberId(bean.getMemberId());
        appBlogPostCommentRespVO.setRespondCommentId(bean.getRespondCommentId());
        appBlogPostCommentRespVO.setContent(bean.getContent());

        return appBlogPostCommentRespVO;
    }

    default List<AppBlogPostCommentRespVO> convertAppList(List<BlogPostCommentDO> blogPostCommentDOList, Map<Long, MemberUserRespDTO> memberMap){
        List<AppBlogPostCommentRespVO> list = new ArrayList<>();
        blogPostCommentDOList.forEach(blogPostCommentDO -> {
            list.add(convertApp(blogPostCommentDO, memberMap.get(blogPostCommentDO.getMemberId())));
        });

        return list;
    }
    default PageResult<AppBlogPostCommentRespVO> convertAppPage(PageResult<BlogPostCommentDO> page, Map<Long, MemberUserRespDTO> memberMap ){
        if ( page == null ) {
            return null;
        }

        PageResult<AppBlogPostCommentRespVO> pageResult = new PageResult<AppBlogPostCommentRespVO>();
        List<AppBlogPostCommentRespVO> list = convertAppList(page.getList(), memberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }
}
